package com.hang.mapstruct;


import com.hang.entity.Task;
import com.hang.model.dto.request.TaskModelReq;
import com.hang.model.vo.TaskInfoDetailVO;
import com.hang.model.vo.TaskInfoVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import java.util.LinkedList;
import java.util.List;

@Mapper(componentModel = "spring")
public interface TaskMapStruct {
    Task taskModelReqToTask(TaskModelReq taskModelReq);

    default List<TaskInfoVO> taskListToTaskInfoVOList(List<Task> taskList){
        List<TaskInfoVO> taskInfoVOList = new LinkedList<>();
        taskList.forEach(
                task -> {
                    taskInfoVOList.add(taskToTaskInfoVO(task));
                }
        );

        return taskInfoVOList;
    }

    @Mapping(source = "taskId",target = "taskId")
    @Mapping(source = "taskType",target = "taskType",qualifiedByName = "typeFormatter")
    @Mapping(source = "priority",target = "priority",qualifiedByName = "priorityFormatter")
    @Mapping(source = "solveStatus",target = "solveStatus",qualifiedByName = "statusFormatter")
    TaskInfoVO taskToTaskInfoVO(Task task);

    @Mapping(source = "taskId",target = "taskId")
    @Mapping(source = "taskType",target = "taskType",qualifiedByName = "typeFormatter")
    @Mapping(source = "priority",target = "priority",qualifiedByName = "priorityFormatter")
    @Mapping(source = "solveStatus",target = "solveStatus",qualifiedByName = "statusFormatter")
    TaskInfoDetailVO taskToTaskInfoDetailVO(Task task);

    @Named("typeFormatter")
    default String typeFormatter(Integer taskType){
        if(taskType.compareTo(1) == 0){
            return "接口开发";
        }else if(taskType.compareTo(2) == 0){
            return "接口调整";
        }else if(taskType.compareTo(3) == 0){
            return "需求变更";
        }else if(taskType.compareTo(4) == 0){
            return "其它";
        }

        return "全部";
    }

    @Named("priorityFormatter")
    default String priorityFormatter(Integer priority){
        if(priority.compareTo(1) == 0){
            return "低";
        }else if(priority.compareTo(2) == 0){
            return "中";
        }else if(priority.compareTo(3) == 0){
            return "高";
        }else if(priority.compareTo(4) == 0){
            return "紧急";
        }

        return "全部";
    }

    @Named("statusFormatter")
    default String statusFormatter(Integer solveStatus){
        if(solveStatus.compareTo(1) == 0){
            return "未处理";
        }else if(solveStatus.compareTo(2) == 0){
            return "处理中";
        }else if(solveStatus.compareTo(3) == 0){
            return "已完成";
        }

        return "全部";
    }
}
